#include<stdio.h>

#define ROW 6
#define COL 7

int row_t[ROW] = {2,0,4,3,4,0};//每一行的和
int col_t[COL] = {4,1,2,2,1,2,1};//每一列的和
//int row_t[ROW]={},col_t[COL] = {};
int es[ROW][COL];
int count = 0;
int iSetCount = 0;

int count_row(int r){
        int i,t = 0;
        for(i = 0; i< COL; i++) t+=es[r][i];
        return t;
}
int count_col(int c){
        int i,t =0;
        for(i = 0; i<ROW; i++) t+= es[i][c];
        return t;
}
int check(){
        int i,j,t;
        for(i = 0; i < ROW; i++){
                if(row_t[i] != count_row(i)) return 0;
        }
        for(i = 0; i < COL; i++){
                if(col_t[i] != count_col(i)) return 0;
        }
        return 1;
}

void show_array(){
        int i,j;
        for(i = 0; i<ROW; i++){
                for(j = 0;j<COL; j++)
                        printf("%d\t",es[i][j]);
                printf("\n");
        }
        printf("-------------------------------------\n");
}

void f(int ni,int nj){
        int i,j;
        if(nj == COL){
                ni++;
                nj = 0;
        }
        if(ni == ROW){
                if(check()){
                        show_array();
                        count++;
                }
                return;
        }
        es[ni][nj] = 0;
        iSetCount ++;
        if(count_row(ni) < row_t[ni] && nj != COL-1 && count_col(nj) <= col_t[nj])
                f(ni,nj+1);
        if(count_row(ni) == row_t[ni]) f(ni+1,0);
        es[ni][nj] = 1;
        if(count_row(ni) < row_t[ni] && nj != COL-1 && count_col(nj) <= col_t[nj])
            f(ni,nj+1);
        if(count_row(ni) == row_t[ni]) f(ni+1,0);
        es[ni][nj] = 0;
}

int main(){
        int i,j;
        //init
        f(0,0);
        printf("%d\n",count);
        printf("iSetCount = %d \n",iSetCount);

        return 0;
}

